<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of quanly_capdo
 *
 * @author Bui
 */
class Quanly_model extends CI_Model {

    private $tbl_quanly = 'gs7s_quanly';

    //put your code here

    public function __construct() {
        parent::__construct();
        $this->load->database();
    }
    //kiễm tra điều login
        function login($username, $password) {
        $this->db->select('id', 'username', 'password');
        $this->db->from('gs7s_quanly');
        $this->db->where('username', $username);
        $this->db->where('password', $password);
        $this->db->limit(1);
       $query = $this->db->get();
        if ($query->num_rows == 1) {
            return $query->result();
        } else {
            return FALSE;
        }
    }
     function active($username) {
        $data = array(
            'trangthai_id' => '2',
        );
        $this->db->where('username', $username);
        $this->db->update('gs7s_quanly', $data);
    }

    function deactive($username) {
        $data = array(
            'trangthai_id' => '1',
        );
        $this->db->where('username', $username);
        $this->db->update('gs7s_quanly', $data);
    }

    function count_all() {
        return $this->db->count_all($this->tbl_quanly);
    }

    function get_paged_list($limit = 10, $offset = 0) {
        $this->db->order_by('id', 'asc');
        return $this->db->get($this->tbl_quanly, $limit, $offset);
    }

    function get_data($id) {
        $this->load->database();
        $query = $this->db->get_where($this->tbl_quanly, array('id' => $id));
        return $query->row_array();
    }
    
    function get_by_id($id){
        $this->db->where('id', $id);
        return $this->db->get($this->tbl_quanly);
    }

    function add($data) {
        $this->db->insert($this->tbl_quanly, $data);
        return $this->db->insert_id();
    }

    function update($id, $data) {
        $this->load->database();
        $this->db->where('id', $id);
        $this->db->update($this->tbl_quanly, $data);
    }

    function delete($id) {
        $this->db->where('id', $id);
        $this->db->delete($this->tbl_quanly);
    }

}
function load_quanly($select, $where) {

        $this->db->select($select);
        $this->db->from('gs7s_quanly');
        $this->db->where($where['key'], $where['value']);
        $this->db->limit(1);
        $query = $this->db->get();
        if ($query->num_rows() == 0)
            return FALSE;
        return $query->result();
}
?>
